package com.sky.mapper;

import com.sky.entity.AddressBook;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AddressBookMapper {
    @Select("select * from address_book where user_id=#{userId}")
    List<AddressBook> list(Long userId);

    @Insert("insert into address_book(user_id, consignee, sex, phone, province_code, province_name, city_code, city_name, district_code, district_name, detail, label) values(#{userId},#{consignee},#{sex},#{phone},#{provinceCode},#{provinceName},#{cityCode},#{cityName},#{districtCode},#{districtName},#{detail},#{label})")
    void add(AddressBook addressBook);

    @Select("select * from address_book where user_id=#{userId} and is_default=#{isDefault}")
    AddressBook getDefault(AddressBook addressBook);

    @Update("update address_book set is_default=#{isDefault} where id=#{id}")
    void setDefault(AddressBook addressBook);


    @Update("update address_book set is_default=#{isDefault} where user_id=#{userId}")
    void cleanDefault(AddressBook addressBook);

    @Select("select * from address_book where user_id=#{userId} and id=#{addressBookId}")
    AddressBook getById(Orders orders);
}
